home *** CD-ROM | disk | FTP | other *** search
/ World of Amiga / World of Amiga.iso / archive / music / oplay1231.lha / src / gentab.c < prev    next >
C/C++ Source or Header  |  1992-10-28  |  1KB  |  51 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. /*--------------------------------------------------------------------------*/
  5. /* The following routine was extracted from posting by Brian Foley.         */
  6. /* Brian Foley        email: bfoley@greatlakes.Central.Sun.COM            */
  7. /* Systems Engineer    smail:    1000 Town Center                            */
  8. /* Sun Microsystems        Suite 1700                                  */
  9. /* GreatLakes Region        Southfield, MI 48075   (313) 352-7070       */
  10. /*--------------------------------------------------------------------------*/
  11.  
  12. int ulaw2linear(unsigned char ulawbyte)
  13. {
  14.     static int exp_lut[8] = { 0, 132, 396, 924, 1980, 4092, 8316, 16764 };
  15.            int sign, exponent, mantissa, sample;
  16.  
  17.     ulawbyte    = ~ulawbyte;
  18.     sign        =  ulawbyte & 0x80;
  19.     exponent    = (ulawbyte >> 4) & 0x07;
  20.     mantissa    =  ulawbyte & 0x0F;
  21.     sample        = exp_lut[exponent] + (mantissa << (exponent + 3));
  22.     if ( sign ) sample = -sample;
  23.     return sample;
  24. }
  25.  
  26. main()
  27. {
  28. int i;
  29.  
  30.     printf("/*\n"
  31.         " * u-law to linear conversion table\n"
  32.         " * generated "__TIME__", "__DATE__"\n"
  33.         " * by D. Champion's gentab\n"
  34.         " * using B. Foley's ulaw2linear()\n"
  35.         " * and a custom formatting routine\n"
  36.         " *\n"
  37.         " * use this table in place of ulaw2linear()\n"
  38.         " * to speed up processing\n"
  39.         " */\n\n");
  40.     printf("signed long ulaw_tab[] = {\n\t");
  41.  
  42.     for (i=0; i<256; i++) {
  43.         printf("0x%08x, ", ulaw2linear(i));
  44.         if ( i%4 == 3 ) printf("\n\t");
  45.     }
  46.  
  47.     printf("0x00000000\n};\n");
  48.  
  49.     exit(0);
  50. }
  51.